//
//  TCCalendarCollectionViewCell.m
//  TCCalendarSelector
//
//  Created by 叮叮 on 2021/5/8.
//

#import "TCCalendarCollectionViewCell.h"
#import "TCCalendar.h"

@interface TCCalendarCollectionViewCell()
@property (nonatomic, weak) CALayer *todayView;
@property (nonatomic, weak) CALayer *selectedView;
@end

@implementation TCCalendarCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    CALayer *todayView = [CALayer layer];
    todayView.frame = self.bounds;
    todayView.backgroundColor = TCCalendar.todayColor.CGColor;
    todayView.cornerRadius = self.bounds.size.width / 2;
    [self.contentView.layer addSublayer:todayView];
    self.todayView = todayView;
    
    CALayer *selectedView = [CALayer layer];
    selectedView.frame = self.bounds;
    selectedView.backgroundColor = TCCalendar.selectedColor.CGColor;
    [self.contentView.layer addSublayer:selectedView];
    self.selectedView = selectedView;
    
    UILabel *textLabel = [[UILabel alloc] initWithFrame:self.bounds];
    textLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:textLabel];
    _textLabel = textLabel;
}

- (void)reloadViews {
    /// 是否选中优先级最高
    if (self.isSelected) {
        /// 选中的状态下，今天视图被隐藏，字体为白色
        _textLabel.textColor = UIColor.whiteColor;
        self.todayView.hidden = YES;
        self.selectedView.hidden = NO;
    } else {
        self.selectedView.hidden = YES;
        if (self.isToday) {
            /// 非选中状态下，如果是今天，则展示今天视图，字体为白色
            _textLabel.textColor = UIColor.whiteColor;
            self.todayView.hidden = NO;
        } else {
            /// 非选中状态下，如果不是今天，则不展示今天视图，字体为黑色
            _textLabel.textColor = UIColor.blackColor;
            self.todayView.hidden = YES;
        }
    }
}

@end
